<template>
    <div>
        <fieldset>
            <legend>存取器</legend>
            <div></div>
        </fieldset>
    </div>
</template>

<script lang="ts">
import { defineComponent, getCurrentInstance, ref } from "vue";
export default defineComponent({
    name: "Home",
    setup() {
        // 存取器：有效控制对对象中成员的访问，通过 getters 和 setters 操作
        class aaa {
            name: string;
            age!: number;
            constructor() {
                this.name = "你大爷";
            }
            // 读取器
            get fullName() {
                return `姓名：${this.name}`;
            }

            // 设置器-------e 参数必填
            set fullName(e) {
                this.name = e;
            }
        }
        let aaa1 = new aaa();

        console.log("读取器----------------------------");
        console.log(aaa1.fullName);

        console.log("设置器----------------------------");
        // 没有设置器的话，fullName 是只读的
        aaa1.fullName = "你二大爷";
        console.log(aaa1.fullName);
        console.log(aaa1.name);
        return {};
    },
});
</script>
